/*
 *  Copyright (c) 2013 The CCP project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
 *  that can be found in the LICENSE file in the root of the web site.
 *
 *   http://www.yuntongxun.com
 *
 *  An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
package com.yuntongxun.ecdemo.ui.chatting.holder;

import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.melink.baseframe.utils.DensityUtils;
import com.melink.bqmmsdk.widget.BQMMMessageText;
import com.yuntongxun.ecdemo.R;
import com.yuntongxun.ecdemo.common.base.CCPTextView;
import com.yuntongxun.ecdemo.ui.chatting.base.EmojiconTextView;


/**
 * @author 容联•云通讯
 * @date 2014-12-9
 * @version 4.0
 */
public class DescriptionViewHolder extends BaseHolder{

	public View chattingContent;
	/**
	 * TextView that display IMessage description.
	 */
	private BQMMMessageText descTextView;

	public TextView readTv;

	public ImageView contentImg;

	//话题布局
	public LinearLayout topicLayout;
	public TextView infoTv;
	public TextView questionTv;
	public TextView answerTv;
	public ImageView questionBtn;
	public ImageView answerBtn;

	public RelativeLayout baseLayout;
	
	/**
	 * @param type
	 */
	public DescriptionViewHolder(int type) {
		super(type);

	}
	
	public BaseHolder initBaseHolder(View baseView , boolean receive) {
		super.initBaseHolder(baseView);

		chattingTime = (TextView) baseView.findViewById(R.id.chatting_time_tv);
		chattingUser = (TextView) baseView.findViewById(R.id.chatting_user_tv);

		descTextView = (BQMMMessageText) baseView.findViewById(R.id.chatting_content_itv);
		descTextView.setSmallEmojiShowSize(DensityUtils.dip2px(baseView.getContext(), 20));
		descTextView.setBigEmojiShowSize(DensityUtils.dip2px(baseView.getContext(), 100));

		checkBox = (CheckBox) baseView.findViewById(R.id.chatting_checkbox);
		chattingMaskView = baseView.findViewById(R.id.chatting_maskview);
		chattingContent = baseView.findViewById(R.id.chatting_content_area);

		//礼物
		contentImg=(ImageView)baseView.findViewById(R.id.chatting_content_iv);

		//话题
		topicLayout=(LinearLayout)baseView.findViewById(R.id.chatting_topic_layout);
		infoTv=(TextView)baseView.findViewById(R.id.chatting_topic_name);
		questionTv=(TextView)baseView.findViewById(R.id.chatting_topic_question_tv);
		answerTv=(TextView)baseView.findViewById(R.id.chatting_topic_answer_tv);
		questionBtn=(ImageView) baseView.findViewById(R.id.chatting_topic_question_img);
		answerBtn=(ImageView)baseView.findViewById(R.id.chatting_topic_answer_img);

		baseLayout=(RelativeLayout)baseView.findViewById(R.id.chatting_item_base_layout);

		if(!receive){
			readTv =(TextView) baseView.findViewById(R.id.tv_read_unread);
		}

		if(receive) {
			type = 7;
			return this;
		}

		
		uploadState = (ImageView) baseView.findViewById(R.id.chatting_state_iv);
		progressBar = (ProgressBar) baseView.findViewById(R.id.uploading_pb);
		type = 8;
		return this;
	}

	public LinearLayout getTopicLayout(){
		if (topicLayout==null){
			topicLayout=(LinearLayout)getBaseView().findViewById(R.id.chatting_topic_layout);
		}
		return topicLayout;
	}

	public TextView getNameTv(){
		if (infoTv==null){
			infoTv=(TextView) getBaseView().findViewById(R.id.chatting_topic_name);
		}
		return infoTv;
	}

	public TextView getQuestionTv(){
		if (questionTv==null){
			questionTv=(TextView) getBaseView().findViewById(R.id.chatting_topic_question_tv);
		}
		return questionTv;
	}
	public TextView getAnswerTv(){
		if (answerTv==null){
			answerTv=(TextView) getBaseView().findViewById(R.id.chatting_topic_answer_tv);
		}
		return answerTv;
	}

	public ImageView getQuestionBtn(){
		if (questionBtn==null){
			questionBtn=(ImageView) getBaseView().findViewById(R.id.chatting_topic_question_img);
		}
		return questionBtn;
	}

	public ImageView getAnswerBtn(){
		if (answerBtn==null){
			answerBtn=(ImageView) getBaseView().findViewById(R.id.chatting_topic_answer_img);
		}
		return answerBtn;
	}

	/**
	 * {@link CCPTextView} Display imessage text 
	 * @return
	 */
	public BQMMMessageText getDescTextView() {
		if(descTextView == null) {
			descTextView = (BQMMMessageText) getBaseView().findViewById(R.id.chatting_content_itv);
		}
		return descTextView;
	}

	//礼物图片
	public ImageView getContentImg(){
		if (contentImg==null){
			contentImg=(ImageView)getBaseView().findViewById(R.id.chatting_content_iv);
		}
		return contentImg;
	}

	public RelativeLayout getBaseLayout(){
		if (baseLayout!=null){
			baseLayout=(RelativeLayout)getBaseView().findViewById(R.id.chatting_item_base_layout);
		}
		return baseLayout;
	}
	
	/**
	 * 
	 * @return
	 */
	public ImageView getChattingState() {
		if(uploadState == null) {
			uploadState = (ImageView) getBaseView().findViewById(R.id.chatting_state_iv);
		}
		return uploadState;
	}
	
	/**
	 * 
	 * @return
	 */
	public ProgressBar getUploadProgressBar() {
		if(progressBar == null) {
			progressBar = (ProgressBar) getBaseView().findViewById(R.id.uploading_pb);
		}
		return progressBar;
	}

	@Override
	public TextView getReadTv() {
		return readTv;
	}

}
